#include "motion.h"

using namespace m3d;

#define SGRAVITY 9.80665f

SVector3F* m3d::ParabolicMotionXUP( SVector3F* out_Position, const SVector3F* vVelocity, float fSec, float* fGravity )
{
	(*out_Position).x = vVelocity->x  * fSec;
	(*out_Position).y = vVelocity->y  * fSec;
	(*out_Position).z = vVelocity->z  * fSec;
	fSec *= fSec;
	if( fGravity )
		(*out_Position).x += ((fSec * .5f) * *fGravity) * -1;
	else
		(*out_Position).x += ((fSec * .5f) * SGRAVITY) * -1;
	return out_Position;
}

SVector3F* m3d::ParabolicMotionZUP( SVector3F* out_Position, const SVector3F* vVelocity, float fSec, float* fGravity )
{
	(*out_Position).x = vVelocity->x  * fSec;
	(*out_Position).y = vVelocity->y  * fSec;
	(*out_Position).z = vVelocity->z  * fSec;
	fSec *= fSec;
	if( fGravity )
		(*out_Position).z += ((fSec * .5f) * *fGravity) * -1;
	else
		(*out_Position).z += ((fSec * .5f) * SGRAVITY) * -1;
	return out_Position;
}

SVector3F* m3d::ParabolicMotionYUP( SVector3F* out_Position, const SVector3F* vVelocity, float fSec, float* fGravity )
{
	(*out_Position).x = vVelocity->x  * fSec;
	(*out_Position).y = vVelocity->y  * fSec;
	(*out_Position).z = vVelocity->z  * fSec;
	fSec *= fSec;
	if( fGravity )
		(*out_Position).y += ((fSec * .5f) * *fGravity) * -1;
	else
		(*out_Position).y += ((fSec * .5f) * SGRAVITY) * -1;
	return out_Position;
}

SVector3F* m3d::ParabolicMotion( SVector3F* out_Position, const SVector3F* vVelocity, float fSec, float* fGravity, M3DAXISINDEX nAxis )
{
	(*out_Position).x = vVelocity->x  * fSec;
	(*out_Position).y = vVelocity->y  * fSec;
	(*out_Position).z = vVelocity->z  * fSec;
	fSec *= fSec;
	if( fGravity )
		((float*)out_Position)[nAxis] += ((fSec * .5f) * *fGravity) * -1;
	else
		((float*)out_Position)[nAxis] += ((fSec * .5f) * SGRAVITY) * -1;
	return out_Position;
}
